/*
Arm Tracker and Glove Demo by Noah Zerkin (noazark AT gmail.com) 2009
Released under GNU GPLv3.0 http://www.opensource.org/licenses/gpl-3.0.html
*/

int handPose(byte[][] fv){

  byte[][] fingerValues = new byte[4][2];
  byte[] fp = new byte[4]; //Finger Pose
  int pose = 0;
  fingerValues = fv;

  for(byte i = 0; i < 4; i++){
    fp[i] = readFingerPose(fingerValues[i][0], fingerValues[i][1]);
  }
  pose = int(fp[0]) * 1000 + int(fp[1]) * 100 + int(fp[2]) * 10 + int(fp[3]);
  return pose;
} 

byte readFingerPose(byte firstKnuckle, byte secondKnuckle){
  byte position = 0;
  boolean firstKnuckleFlexed = false;
  boolean secondKnuckleFlexed = false;
  if(firstKnuckle > 15){
    firstKnuckleFlexed = true;
  }
  if(secondKnuckle > 30){
    secondKnuckleFlexed = true;
  }
  if(!firstKnuckleFlexed && !secondKnuckleFlexed){
    position = 1;
    return position;
  }
  if(firstKnuckleFlexed && !secondKnuckleFlexed){
    position = 2;
    return position;
  }
  if(!firstKnuckleFlexed && secondKnuckleFlexed){
    position = 3;
    return position;
  }
  if(firstKnuckleFlexed && secondKnuckleFlexed){
    position = 4;
    return position;
  }
  return position;
}
